<?php
/*
*	专题内容分类相关模型
*/
defined('BASEPATH') OR exit('No direct script access allowed');
class SpecialContentType_m extends MY_Model {
    public function __construct()
    {
        parent::__construct();
        $this->table='special_contenttype';
    }
    //查询单条分类信息
    public function sel($where=array(),$field="*"){
        $this->com_where($where);
        $this->db->select($field);
        $query=$this->db->get($this->table);
        $data=$query->row_array();
        return $data;
    }
    //专题内容分类
    public function selall($where=array(),$field='A.*,B.displayname',$order='A.id desc'){
        $data = array();
        $this->com_where($where);
        $this->db->select($field);
         $this->db->order_by($order);
        $this->db->from($this->table." as A");
        $this->db->join('adminuser as B','A.userid=B.id');
        $query = $this->db->get();
        $list = $query->result_array();
        return $list;
    }
    //添加分类
    public function add($data){
        $data['addtime']=time();
        $this->db->insert($this->table,$data);
        return $this->db->insert_id();
    }
    //编辑分类
    public function edit($where,$data){
        $this->com_where($where);
        $this->db->update($this->table,$data);
        return $this->db->affected_rows();
    }
    //删除分类
    public function del($where)
    {
        $this->com_where($where);
        $this->db->delete($this->table);
        return $this->db->affected_rows();
    }
    //文章关联数写入（自增和自减）
    public function specialContent_rnum($id,$inc=1,$num=1){
        if($inc==1){
            $str='`rnum`+'.$num;
          $this->db->set('rnum',$str,false);
        }else{
            $str='`rnum`-'.$num;
          $this->db->set('rnum',$str,false);
        }
        $where_cur['id']=array('=',$id);
        $this->com_where($where_cur);
        $this->db->update($this->table);
        return $this->db->affected_rows();
    }
}
?>